package com.itheima.lambda;

public class Test3 {

    public static void main(String[] args) {
        //lambda实现 接口引用指向实现类对象
        StringHandler s1 = (String msg) -> {
            System.out.println("我是lambda实现" + msg);
        };
        s1.printMessage("HelloWorld");


        useStringHandler(new StringHandler() {
            @Override
            public void printMessage(String msg) {
                System.out.println("我是匿名内部类" + msg);
            }
        });


        //lambda实现
        useStringHandler(msg -> System.out.println("我是lambda表达式" + msg));

        /*
        lambda使用前提：
            1.要有函数式接口
            2.lambda表达式不能独立存在，必须结合上下文使用

         */

    }

    public static void useStringHandler(StringHandler stringHandler) {
        stringHandler.printMessage("HelloWorld");
    }

}

@FunctionalInterface
interface StringHandler {
    void printMessage(String msg);
}